package com.xxx.modules.sys.service.impl;

import com.xxx.modules.sys.domain.SysUserTextSupportDomain;
import com.xxx.modules.sys.service.SysUserTextSupportService;
import com.xxx.modules.sys.service.UserTextSupportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by ChenXuefei on 2017/10/17.
 */
@Service("userTextSupportService")
public class UserTextSupportServiceImpl implements UserTextSupportService {

    @Autowired
    private SysUserTextSupportService sysUserTextSupportService;

    @Override
    public void addUserTextSupport(String supportId, String textId) {
        SysUserTextSupportDomain sysUserTextSupportDomain = new SysUserTextSupportDomain();
        sysUserTextSupportDomain.setTextId(Long.valueOf(textId));
        sysUserTextSupportDomain.setSupportId(Long.valueOf(supportId));
        // 0 点赞  1 取消点赞
        sysUserTextSupportDomain.setState(0);
        sysUserTextSupportDomain.setCreateTime(new Date());
        sysUserTextSupportDomain.setUpdateTime(sysUserTextSupportDomain.getCreateTime());
        sysUserTextSupportService.add(sysUserTextSupportDomain);
    }

    @Override
    public void updateUserTextSupport(String supportId, String textId) {
        SysUserTextSupportDomain sysUserTextSupportDomain = new SysUserTextSupportDomain();
        sysUserTextSupportDomain.setTextId(Long.valueOf(textId));
        sysUserTextSupportDomain.setSupportId(Long.valueOf(supportId));

        List<SysUserTextSupportDomain> sysUserTextSupportDomains = sysUserTextSupportService.queryByList(sysUserTextSupportDomain);
        if(sysUserTextSupportDomains!=null&&sysUserTextSupportDomains.size()>0){
            SysUserTextSupportDomain userTextSupportDomain = sysUserTextSupportDomains.get(0);
            userTextSupportDomain.setUpdateTime(new Date());
            //0 点赞  1 取消点赞
            userTextSupportDomain.setState(1);
            sysUserTextSupportService.updateBySelective(userTextSupportDomain);
        }
    }
}
